package com.sxt.controller;

import com.sxt.common.DataGridView;
import com.sxt.domain.Bills;
import com.sxt.service.BillsService;
import com.sxt.vo.BillsVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.Map;

@Controller
@RequestMapping("bills")
public class BillsController {
    
    @Autowired
    private BillsService billsService;

    /**
     * 跳转到主页
     */
    @RequestMapping("toIndex")
    public String toIndex(){
        return "index";
    }

    /**
     * 查询账单
     */
    @RequestMapping("queryAllBills")
    @ResponseBody
    public DataGridView queryAllBills(BillsVo billsVo){
        return this.billsService.queryAllBills(billsVo);
    }

    /**
     * 添加账单
     */
    @RequestMapping("addBills")
    @ResponseBody
    public Map<String,Object> addBills(Bills bills){
        Map<String,Object> map=new HashMap<>();
        try {
            this.billsService.addBills(bills);
            map.put("code",200);
            map.put("msg","添加成功");
        }catch (Exception e){
            e.printStackTrace();
            map.put("code",-1);
            map.put("msg","添加失败");
        }
        return map;
    }


}
